/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/9/12 10:29
 * @Copyright
 */
package itSystemCase2;
//汽车业务
public class CarOpration {
    Car[] vehicle = new Car[12];

    //初始化数据
    public void init() {
        vehicle[0] = new Sedan("京NY28588", "宝马", 800, "x6");
        vehicle[1] = new Sedan("京CNY3284", "宝马", 600, "550i");
        vehicle[2] = new Sedan("京NT37465", "别克", 300, "林荫大道");
        vehicle[3] = new Sedan("京NT96968", "别克", 600, "GL8");
        vehicle[4] = new PassengerCar("京656675", "金杯", 800, 16);
        vehicle[5] = new PassengerCar("京8696997", "金龙", 800, 16);
        vehicle[6] = new PassengerCar("京9696996", "金杯", 1500, 34);
        vehicle[7] = new PassengerCar("京8696998", "金龙", 1500, 34);
        vehicle[8] = new Lorry("京MH98725", "一汽解放", 50, 2);
        vehicle[9] = new Lorry("京L593216", "重庆红岩", 50, 1);
        vehicle[10] = new Lorry("京NU98631", "一汽解放", 50, 1);
        vehicle[11] = new Lorry("京CY56312", "重庆红岩", 50, 2);
    }

    //租车:根据用户提供的条件去汽车数组中查找相应车辆返回
    //如果租赁的是客车，需要的条件：品牌、座位数、型号null
    //如果租赁的是轿车，需要的条件：品牌、型号、座位数0
    //入锅租赁的是卡车，需要的条件：品牌、吨位0
    public Car motoLeaseOut(String brand, String type, int seat,int tonnage) {
        Car moto = null;
        for (Car mymoto : vehicle) {
            if (mymoto instanceof Sedan) {
                Sedan sedan = (Sedan) mymoto;
                if (sedan.getBrand().equals(brand) && sedan.getType().equals(type)) {
                    moto = sedan;
                    break;
                }
            } else if (mymoto instanceof PassengerCar){
                PassengerCar passengerCar = (PassengerCar) mymoto;
                if (passengerCar.getBrand().equals(brand) && passengerCar.getSeatCount() == seat) {
                    moto = passengerCar;
                    break;
                }
            }else {
                Lorry lorry=(Lorry) mymoto;
                if (lorry.getBrand().equals(brand) && lorry.getTonnage()==tonnage){
                    moto=lorry;
                    break;
                }
            }
        }
        return moto;
    }
}


